/*******************************************************************************
 * Copyright (c) 2012 March and Conquest.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package mrusanov.towers.resources;

public class PlayerIncome extends ResourceBase {

	@Override
	public String toString() {
		return "PlayerIncome [bricks=" + getBricks() + ", gems=" + getGems() + ", beasts=" + getBeasts() + "]";
	}

	@Override
	public void subtractBricks(int bricks) {
		this.bricks = subtractWithoutBeingZero(this.bricks, bricks);
	}

	@Override
	public void subtractGems(int gems) {
		this.gems = subtractWithoutBeingZero(this.gems, gems);
	}

	@Override
	public void subtractBeasts(int beasts) {
		this.beasts = subtractWithoutBeingZero(this.beasts, beasts);
	}

	private int subtractWithoutBeingZero(int minuend, int subtrahend) {
		int result = minuend - subtrahend;
		if (result < 1) {
			return 1;
		} else {
			return result;
		}
	}

	@Override
	public PlayerIncome clone() {
		PlayerIncome income = new PlayerIncome();
		income.beasts = beasts;
		income.bricks = bricks;
		income.gems = gems;
		return income;
	}
}
